<?php

namespace app\command;

use app\model\table\log\OperateLog;
use app\model\table\union\Union;
use app\model\table\user\User;
use app\model\tablenot\tool\RedisService;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Db;


/**
 * @title 定时任务
 */
class commandRankUnion extends Command
{
    protected function configure()
    {
        $this->setName('commandRankUnion')->setDescription("计划任务 commandRankUnion");//
    }

    /**
     *   工会赛季排行榜
     */
    protected function execute(Input $input, Output $output)
    {
        $sql = "select union_id,sum(score) as score from app_user group by union_id";
        $countRes = Db::query($sql);
        foreach ($countRes as $val){
            $postData = array(
                'id' => $val['union_id'],
                'score' => $val['score'],
            );
            Union::instance()->updateOne($postData);
        }
        $output->writeln('success');
    }
}
